﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonWithEvents
{
    class Person
    {
        public event PersonEventHandler FirstNameChanged;
        private event PersonEventHandler LastNameChanged;
        private event PersonEventHandler GenderChanged;
        private event PersonEventHandler BirthDateChanged;

        private string firstName;
        private string lastName;
        private string gender;
        private string birthDate;

        public Person(string firstName, string lastName, string gender, string birthDate)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.gender = gender;
            this.birthDate = birthDate;
            this.LastNameChanged += delegate
            {
                Console.WriteLine("Last name changed");
            };

            this.FirstNameChanged += delegate
            {
                Console.WriteLine("First name changed");
            };

            this.GenderChanged += delegate
            {
                Console.WriteLine("Gender changed");
            };

            this.BirthDateChanged += delegate
            {
                Console.WriteLine("Birth date changed");
            };

        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                firstName = value;
                this.OnFirstNameChanged();
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                lastName = value;
                this.OnLastNameChanged();
            }
        }

        public string Gender
        {
            get
            {
                return gender;
            }
            set
            {
                gender = value;
                this.OnGenderChanged();
            }
        }

        public string BirthDate
        {
            get
            {
                return birthDate;
            }
            set
            {
                birthDate = value;
                this.OnBirthDateChanged();
            }
        }

        protected void OnFirstNameChanged()
        {
            if (this.FirstNameChanged != null)
            {
                this.FirstNameChanged(this, new PersonEventHandlerArgs());
            }
        }

        protected void OnLastNameChanged()
        {
            if (this.LastNameChanged != null)
            {
                this.LastNameChanged(this, new PersonEventHandlerArgs());
            }
        }

        protected void OnGenderChanged()
        {
            if (this.GenderChanged!=null)
            {
                this.GenderChanged(this, new PersonEventHandlerArgs());
            }
        }

        protected void OnBirthDateChanged()
        {
            if (BirthDateChanged != null)
            {
                this.BirthDateChanged(this, new PersonEventHandlerArgs());
            }
        }



        
    }
}
